let myChart = {};

function splitData(rawData) {
	var categoryData = [];
	var values = [];
	var vols = [];
	var macds = [];
	var difs = [];
	var deas = [];
	for (var i = 0; i < rawData.length; i++) {
		categoryData.push(rawData[i].splice(0, 1)[0]);
		values.push(rawData[i])
		vols.push(rawData[i][4]);
		macds.push(rawData[i][6]);
		difs.push(rawData[i][7]);
		deas.push(rawData[i][8]);
	}
	return {
		categoryData: categoryData,
		values: values,
		vols: vols,
		macds: macds,
		difs: difs,
		deas: deas
	};
}

function fenshi(idName, datanumber, timenumber) {
	let echarts = require('echarts'),
		main = document.getElementById(idName);
	let parent = $(main.parentNode);
	main.style.width = parent.width() + 'px';
	main.style.height = parent.height() + 'px';

	myChart = echarts.init(main);

	let option = {
    backgroundColor:"#fff",
    borderColor: 'red',
    legend: {
        textStyle: {
            color: 'red'
        }
    },
		tooltip: {
			trigger: 'axis',
			position: function(pt) {
				// console.log(pt)
				var res = pt[0] + '<br/>'
				// res = '时间：'+pt[0].name+'<br/>'
				// res = res + '价格:' + pt[0].data.value+'<br/>';
				return res;
			}
		},
		grid: [{
			left: '5%',
			right: '12%',
			top: '5%'
		}],
		xAxis: [{
			type: 'category',
			boundaryGap: false,
			data: timenumber,
      axisLine: {
      	onZero: false,
      	lineStyle: {
      		color: '#FF3C39',
      	}
      },
			axisLabel: {
        interval:10,
        rotate:30,
				show: true,
				textStyle: {
					color: '#fff'
				}
			},
      splitLine: {
      	show: false
      },
      splitNumber: 20,
		}],
		yAxis: [{
			type: 'value',
			boundaryGap: ['20%', '20%'],
			axisLabel: {
				show: true,
				interval: 'auto',
				formatter: '{value}',
				textStyle: {
					color: function(params) {
						var colorList;
						if (params > 0) {
							colorList = '#DE2C0C';
						} else if (params < 0) {
							colorList = '#078307';
						} else {
							colorList = '#ffffff';
						}
						return colorList;
					}

				}
			},
      axisLine: {
      	lineStyle: {
      		color: '#FF3C39',
      	}
      },
			position: 'right'
		}],
		dataZoom: [{
				type: 'inside',
				start: 80,
				end: 100
			},
			// {
			// 	start: 50,
			// 	end: 100,
			// 	handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
			// 	handleSize: '80%',
			// 	handleStyle: {
			// 		color: '#fff',
			// 		shadowBlur: 3,
			// 		shadowColor: 'rgba(0, 0, 0, 0.6)',
			// 		shadowOffsetX: 2,
			// 		shadowOffsetY: 2
			// 	}
			// }
		],
		series: [{
			name: '当前价格',
			type: 'line',
			smooth: true,
			symbol: 'none',
			sampling: 'average',
			itemStyle: {
				color: '#449CD4'
			},
			areaStyle: {
				color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
					offset: 0,
					color: '#DEE6F2'
				}])
			},
			data: datanumber
		}]
	};
	myChart.setOption(option);
}

export {
	fenshi
};
